package cn.cool.domain.activity.service.trial.node;

import cn.cool.domain.activity.model.entity.MarketProductEntity;
import cn.cool.domain.activity.model.entity.TrialBalanceEntity;
import cn.cool.domain.activity.service.trial.AbstractGroupBuyMarketSupport;
import cn.cool.domain.activity.service.trial.factory.DefaultActivityStrategyFactory;
import cn.cool.types.design.framework.tree.StrategyHandler;
import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
@Slf4j
public class SwitchNode extends AbstractGroupBuyMarketSupport<MarketProductEntity, DefaultActivityStrategyFactory.DynamicContext, TrialBalanceEntity> {
    @Resource
    private MarketNode marketNode;

    @Override
    public TrialBalanceEntity doApply(MarketProductEntity requestParameter, DefaultActivityStrategyFactory.DynamicContext dynamicContext) throws Exception {
        log.info("活动域-SwitchNode-开关节点.入参: {}, 上下文: {}", JSONUtil.toJsonStr(requestParameter), JSONUtil.toJsonStr(dynamicContext));

        return router(requestParameter, dynamicContext);
    }

    @Override
    public StrategyHandler<MarketProductEntity, DefaultActivityStrategyFactory.DynamicContext, TrialBalanceEntity> get(MarketProductEntity requestParameter, DefaultActivityStrategyFactory.DynamicContext dynamicContext) throws Exception {
        return marketNode;
    }
}
